<?php

namespace App\Admin\Controllers;

use App\Models\TcmDongqipointDetail;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TcmDongqipointDetailController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TcmDongqipointDetail(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('pinyin');
            $grid->column('position');
            $grid->column('picture')->image('',50,50);
            //$grid->column('shareImg');
            //$grid->column('indications');
            //$grid->column('concretPosition');
            //$grid->column('locate');
            //$grid->column('acupuncture');
            //$grid->column('caution');
            //$grid->column('application');
            //$grid->column('created_at');
            //$grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TcmDongqipointDetail(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('pinyin');
            $show->field('position');
            $show->field('picture')->image('',100,100);
            $show->field('shareImg')->image('',100,100);
            $show->field('indications');
            $show->field('concretPosition');
            $show->field('locate')->json();
            $show->field('acupuncture');
            $show->field('caution');
            $show->field('application')->unescape()->as(function ($html) {
				return $html;
			});
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TcmDongqipointDetail(), function (Form $form) {
			$form->tab('基本信息', function (Form $form) {
				$form->display('id');
				$form->text('name');
				$form->text('pinyin');
				$form->text('position');
				$form->image('picture')->uniqueName()->autoUpload()->saveFullUrl();
				$form->image('shareImg')->uniqueName()->autoUpload()->saveFullUrl();
			});
			$form->tab('主治', function (Form $form) {
				$form->array('indications','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
					$table->image('image','图片')->uniqueName()->autoUpload()->saveFullUrl();
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			$form->tab('部位', function (Form $form) {
				$form->array('concretPosition','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
					$table->image('image','图片')->uniqueName()->autoUpload()->saveFullUrl();
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			
			$form->tab('针刺法', function (Form $form) {
				$form->array('acupuncture','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
					$table->image('image','图片')->uniqueName()->autoUpload()->saveFullUrl();
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			$form->tab('注意', function (Form $form) {
				$form->array('caution','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
					$table->image('image','图片')->uniqueName()->autoUpload()->saveFullUrl();
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
            
			$form->tab('取穴', function (Form $form) {
				$form->array('locate','', function ($table) {
					$table->text('title','标题');
					$table->editor('content','内容');
					$table->text('author','作者');
					$table->image('image','图片')->uniqueName()->autoUpload()->saveFullUrl();
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			
            
			$form->tab('应用', function (Form $form) {
                $form->editor('application');
			});
 
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
